<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas {
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <canvas width="800" height="600"></canvas>
    <script>
        window.onload = function () {
            //1:获取canvas对象
            let c = document.querySelector('canvas');
            //2：创建实例
            let ctx = c.getContext('2d');
            ctx.moveTo(100,100);
            ctx.lineTo(100,300);
            ctx.lineTo(300,300);
            ctx.lineTo(300,100);
            ctx.closePath();

            ctx.moveTo(120,120);
            ctx.lineTo(280,120);
            ctx.lineTo(280,280);
            ctx.lineTo(120,280);
            ctx.closePath();
            ctx.lineWidth = '10'
            ctx.stroke();
            ctx.fillStyle = 'red';
            ctx.fill()
        }
    </script>
</body>

</html>